package com.example.model;

import java.io.ByteArrayInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * @Classname FormMulit
 * @Description TODO
 * @Date 2023/4/25 17:54
 * @Created by XiongXiong
 * @Author: X.I.O
 */
public class FormMulit {

    private byte[] bytes;

    private String fileName;

    private String fileType;

    public byte[] getBytes() {
        return bytes;
    }

    public void setBytes(byte[] bytes) {
        this.bytes = bytes;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public String getFileType() {
        return fileType;
    }

    public void setFileType(String fileType) {
        this.fileType = fileType;
    }

    public FormMulit(byte[] bytes, String fileName, String fileType) {
        this.bytes = bytes;
        this.fileName = fileName;
        this.fileType = fileType;
    }

    public void wirteFile(byte[] bytes, String path) throws IOException {
        InputStream in=null;
        FileOutputStream fos =null;
        try {
            in=new ByteArrayInputStream(bytes);
            fos=new FileOutputStream(path);
            byte[] b = new byte[1024];
            while ((in.read(b)) != -1) {
                // 写入数据
                fos.write(b);
            }
            fos.flush();
            fos.close();
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            if(fos!=null){
                try {
                    fos.close();
                }catch (IOException e){
                    e.printStackTrace();
                }
            }
        }
    }
}
